﻿using System;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_DamageTempModify : SkillEffective
    {
        protected override ISerializeCustomPOD OnExecute(SkillEffectiveData data, Unit target, SkillEffectiveContext context, int effectiveIndex, out SkillEffectiveResponse startResp)
        {
            startResp = null;
            if (data.effectiveConfig.customConfig is SkillEffective_DamageTempModify_ConfigData rConfig && context.param is SkillCorrect rCorrect)
            {
                var rAttacker = context.skill.executer;
                rCorrect.tempDamageModify = rConfig.damageModify.GetValue(rAttacker, target, LFloat.zero);
                rCorrect.tempHurtModify = rConfig.hurtModify.GetValue(rAttacker, target, LFloat.zero);
            }

            return null;
        }

        protected override ISerializeCustomPOD OnActionExecute(SkillEffectiveData data, SkillActionNode action, Unit target, ref SkillEffectiveContext context, int effectiveIndex)
        {
            if (action.customConfig is SkillEffectiveAction_DamageTempModify_ConfigData rConfig && context.param is SkillCorrect rCorrect)
            {
                var rAttacker = context.skill.executer;
                rCorrect.tempDamageModify = rConfig.damageModify?.GetValue(rAttacker, target, context) ?? LFloat.zero;
                rCorrect.tempHurtModify = rConfig.hurtModify?.GetValue(rAttacker, target, context) ?? LFloat.zero;
            }

            return null;
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            return $"伤害临时修正";
        }
#endif
    }
}